<?php
/**
 * @version		$Id: banner.php 10878 2008-08-30 17:29:13Z willebil $
 * @package		Joomla
 * @subpackage	Banners
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
jimport ( 'joomla.application.component.controller' );

class ManagerControllerPond extends JController {

	var $urldirect = "";
	var $mainframe = "";

	function __construct() {
		parent::__construct();

		$this->view = & $this->getView('pond', 'html');
		$this->urldirect = 'index.php?option=com_manager&c=pond';
		$this->mainframe = JFactory::getApplication();
	}

	function display() {
		$this->view->display();
	}

	function add() {
		ManagerHelper::showToolBarForm('Add New Pond');
		$this->view->addForm();
	}

	function edit() {
		ManagerHelper::showToolBarForm('Edit Pond');
		$this->view->addForm();
	}

	function cancel() {
		$this->mainframe->redirect($this->urldirect);
	}

	function save() {
		$row = & JTable::getInstance('Pond', 'Table');
		$post = JRequest::get('post', Pond);
		
		if (empty($post['id'])) {
			$randPass = JUserHelper::genRandomPassword();
			$data = array(
				'name' => $post['name'],
				'username' => $post['email'],
				'email' => $post['email'],
				'groups' => array(ManagerHelper::ROLE_AGENCY),
				'block' => 0,
				'password' => $randPass, // set the password
				'password2' => $randPass, // confirm the password
				'sendEmail' => 1 // should the user receive system mails?
			);
			$user = ManagerHelper::createNewUser($data);
			
			if ($user)  {
				$post['user_id'] = $user->id;
			}
		}

		$row->save($post);
		$this->mainframe->redirect($this->urldirect);
	}
	
	function delete() {
		$row = & JTable::getInstance('Pond', 'Table');
		
		$cid = JRequest::getVar('cid');		
		if(!empty($cid)) {
			$row->deleteAll($cid);
		}
		
		$this->mainframe->redirect($this->urldirect);
	}
	
	function toExcel() {
		ManagerHelper::formatExcel('Pond');
	}
	
	function toPDF() {
		ManagerHelper::formatPdf('Pond');
	}
	
	function toWord() {
		
	}
}

?>